/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import client.controleur.View;
import client.locale.ModeleLocal;
import client.controleur.Controleur;
import client.controleur.InterfaceModele;
import client.distant.ModeleDistant;
import Lib.Transport;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 *
 * @author Mickael
 */
public class Main {

    public static String host;
    public static Integer port;

    public static Properties load(String s) throws IOException, FileNotFoundException {
        Properties prop = new Properties();
        InputStream iS = Main.class.getClassLoader().getResourceAsStream(s);
        try {
            prop.load(iS);
            return prop;
        } finally {
            iS.close();
        }
    }
    static final String lang = "Fr";

    public static void main(String[] args) throws IOException {
        Properties modeleProperties = load("client/modele.properties");
        Controleur c = new Controleur(lang);
        View v = new View(lang);
        c.setView(v);
        /*Class classe = Main.class.getClassLoader().loadClass(modeleProperties.getProperty("modeleClass"));
        InterfaceModele m = (InterfaceModele)classe.newInstance();*/
        InterfaceModele iM = null;
        if (modeleProperties.getProperty("modeleClass").equals("ModeleLocal")) {
            iM = new ModeleLocal();
        } else if (modeleProperties.getProperty("modeleClass").equals("ModeleDistant")) {
            Transport t = new Transport();
            ModeleDistant mD = new ModeleDistant(c);
            Properties props = load("client/config.properties");
            host = props.getProperty("host");
            try {
                port = Integer.parseInt(props.getProperty("port"));
                mD.creerCoucheTransport(t, host, port);
            } catch (NumberFormatException ex) {
                System.err.println("Erreur au niveau du fichier properties");
            }
            //mD.setHost(host);
            //mD.setPort(port);
            iM = mD;

        }
        c.setInterfaceModele(iM);
        v.setaL(c);
        v.setwL(c);
        v.go();
        /*
         * instanceof
        Properties props = load("client/config.properties");
        host = props.getProperty("host");
        port = Integer.parseInt(props.getProperty("port"));
        System.out.println(host + ":" + port);
         */
    }
}
